package generic.queue;


public abstract class IHandler<T> implements Runnable,Cloneable{

	private IEvent<T> event;
	private EventQueue<T> queue;

	@Override
	public void run() {		
		if(handle(getEvent().getContext()))
			getQueue().getProducerQueue().add(getEvent());
		else
			getQueue().publish(getEvent());
	}

	public abstract boolean handle(T context);

	public IEvent<T> getEvent() {
		return event;
	}

	public void setEvent(IEvent<T> event) {
		this.event=event;
	}
	
	public IHandler<T> clone() throws CloneNotSupportedException {
		return (IHandler<T>) super.clone();		
	}

	public EventQueue<T> getQueue() {
		return queue;
	}

	public void setQueue(EventQueue<T> queue) {
		this.queue = queue;
	}
}
